home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / demobook / bookdraw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  7.3 KB  |  293 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <stdio.h>
  18. #include <math.h>
  19. #include <gl.h>
  20. #include <device.h>
  21. #include <sys/time.h>
  22. #include "exbookglo.h"
  23. #include "exglobals.h"
  24.  
  25. short highlightcolor = 13;
  26. extern Matrix *dummy;
  27.  
  28. float flatpage[4][2] = { 
  29.     {0.0, 0.0},
  30.     {PGWIDTH, 0.0},
  31.     {PGWIDTH, PGHEIGHT},
  32.     {0.0, PGHEIGHT}
  33.     };
  34.  
  35.  
  36. float texbox[4][3] = {  {0.2, 0.33, 0.0},
  37.                         {1.8, 0.33, 0.0},
  38.                         {1.8, 2.0, 0.0},
  39.                         {0.2, 2.0, 0.0} };
  40.  
  41. float texnorm[3] = {0.0, 0.0, 1.0};
  42.  
  43. float texpnts[4][2] = { {0.0, 0.0},
  44.                         {1.0, 0.0},
  45.                         {1.0, 1.0},
  46.                         {0.0, 1.0} };
  47.  
  48. /*
  49.    float tex_props[] = {TX_MINFILTER,TX_MIPMAP_BILINEAR,
  50.                          TX_MAGFILTER,TX_BILINEAR,TX_NULL};
  51.    float env_props[] = {TV_NULL};
  52.  
  53. */
  54.  
  55.  
  56. /*  routines in this file are:
  57.  
  58.     void    drawscene    (frame)
  59.     void    pickdrawscene    (frame)
  60. */
  61.  
  62. void close_book()
  63. {
  64.             resetshelfcolors();
  65.             unhighlighticon();
  66.             OPENBOOK = FALSE;
  67.             currentbook = -1;
  68.             curgroup = NULL;
  69.             leftpage = NULL;
  70.             middlepage = NULL;
  71.             rightpage = NULL;
  72.             dobookview();
  73. /*
  74.             setcursor(0,0,0);
  75. */
  76.  
  77. }
  78. /************************************************************
  79. *
  80. * Draw the outline of a flat page.  This is used to drag
  81. * the page when the groups are re-arranged in that window.
  82. *
  83. ************************************************************/
  84. void overdrawflatpage(int i)
  85. {
  86.    color(0);
  87.    clear();
  88.    color(3);
  89.    bgnline();
  90.    v2f(flatpage[0]);
  91.    v2f(flatpage[1]);
  92.    v2f(flatpage[2]);
  93.    v2f(flatpage[3]);
  94.    v2f(flatpage[0]);
  95.    endline(); 
  96. }
  97.  
  98. /************************************************************
  99. *
  100. * Draw the flat page.  This is used to draw a page in the 
  101. * index window and in the re-arrange group window.
  102. *
  103. ************************************************************/
  104. void drawflatpage(int i)
  105. {
  106.    loadname(i);
  107.    c3s(morecolors[117]);
  108.    bgnpolygon();
  109.    v2f(flatpage[0]);
  110.    v2f(flatpage[1]);
  111.    v2f(flatpage[2]);
  112.    v2f(flatpage[3]);
  113.    endpolygon(); 
  114.    c3s(morecolors[Black]);
  115.    bgnline();
  116.    v2f(flatpage[0]);
  117.    v2f(flatpage[1]);
  118.    v2f(flatpage[2]);
  119.    v2f(flatpage[3]);
  120.    v2f(flatpage[0]);
  121.    endline(); 
  122. }
  123.  
  124. void drawicon_img(Boolean highlight_flag, struct icntmpltstruct *ic)
  125. {
  126.    float vect[3];
  127.    int i;
  128.  
  129.    c3s(morecolors[White]);
  130. /*ERROR I broke texture mapping when I deleted the lighting stuff from bookinit.c */
  131.    lmbind(MATERIAL,1);
  132.    texbind(TX_TEXTURE_0, ic->tex_id);
  133.    tevbind(TV_ENV0, 1);
  134.    bgnpolygon();
  135.       n3f(texnorm); t2f(texpnts[3]); v3f(texbox[3]);
  136.       n3f(texnorm); t2f(texpnts[2]); v3f(texbox[2]);
  137.       n3f(texnorm); t2f(texpnts[1]); v3f(texbox[1]);
  138.    endpolygon();
  139.    bgnpolygon();
  140.       n3f(texnorm); t2f(texpnts[3]); v3f(texbox[3]);
  141.       n3f(texnorm); t2f(texpnts[1]); v3f(texbox[1]);
  142.       n3f(texnorm); t2f(texpnts[0]); v3f(texbox[0]);
  143.    endpolygon();
  144.  
  145.    lmbind(MATERIAL,0);
  146.    texbind(TX_TEXTURE_0, 0);
  147.    tevbind(TV_ENV0, 0);
  148. }
  149.  
  150. void print_poly(struct icntmpltstruct *ic)
  151. {
  152.    int i, j, k, limit;
  153.    struct polylist *curpoly;
  154.  
  155.       curpoly = ic->poly;
  156.       limit = ic->numpoly;
  157.       for (j = 0; j < limit; j++)
  158.          {
  159.          k = 0;
  160.          if (curpoly->poly >= 0)
  161.             {
  162.             printf(" p\n ");
  163.             while (curpoly != NULL && curpoly->ndcs[k] >= 0)
  164.                {
  165. printf(" %d  %f %f %f \n", curpoly->ndcs[k], icon_verts[curpoly->ndcs[k]+0],
  166.                       icon_verts[curpoly->ndcs[k]+1],
  167.                       icon_verts[curpoly->ndcs[k]+2]);
  168.                k++;
  169.                }
  170.             }
  171.          k = 0;
  172.          if (curpoly->line >= 0)
  173.             {
  174.             printf(" l\n ");
  175.             while (curpoly != NULL && curpoly->ndcs[k] >= 0)
  176.                {
  177. printf(" %d  %f %f %f \n", curpoly->ndcs[k], icon_verts[curpoly->ndcs[k]+0],
  178.                       icon_verts[curpoly->ndcs[k]+1],
  179.                       icon_verts[curpoly->ndcs[k]+2]);
  180.                k++;
  181.                }
  182.             }
  183.          }
  184. }
  185.  
  186. /************************************************************
  187. *
  188. * Draw a WorkSpace icon.  Assume that the transformation
  189. * matrices are already set up.
  190. *
  191. ************************************************************/
  192. void drawicon_geom(Boolean selection_flag, struct icntmpltstruct *ic)
  193. {
  194.    int i, j, k, limit;
  195.    struct polylist *curpoly;
  196.  
  197.       curpoly = ic->poly;
  198.       limit = ic->numpoly;
  199.       for (j = 0; j < limit; j++)
  200.          {
  201.          k = 0;
  202.          if (curpoly->poly >= 0)
  203.             {
  204.             c3s(morecolors[curpoly->poly]);
  205.             bgnpolygon();
  206.             while (curpoly != NULL && curpoly->ndcs[k] >= 0)
  207.                {
  208.                v2f((float*)icon_verts[curpoly->ndcs[k]]);
  209.                k++;
  210.                }
  211.             endpolygon();
  212.             }
  213.          k = 0;
  214.          if (curpoly->line >= 0)
  215.             {
  216.             c3s(morecolors[curpoly->line]);
  217.             bgnline();
  218.             while (curpoly != NULL && curpoly->ndcs[k] >= 0)
  219.                {
  220.                v2f((float*)icon_verts[curpoly->ndcs[k]]);
  221.                k++;
  222.                }
  223.             endline();
  224.             }
  225.          curpoly++;
  226.          }
  227. }
  228.  
  229. /************************************************************
  230. *
  231. * Draw all the icons on a flat page.  Does the translates. 
  232. *
  233. ************************************************************/
  234. void drawflaticons(thispage)
  235. struct pagestruct *thispage;
  236. {
  237.    struct iconstruct *tmpiconptr;
  238.  
  239.    tmpiconptr = thispage->fronticons;
  240.    while (tmpiconptr != NULL)
  241.       {
  242.       pushmatrix();
  243.       translate(tmpiconptr->xposition_ndx*2.0, tmpiconptr->yposition_ndx*2.0, 0.0);
  244.       drawicon_geom(0,tmpiconptr->iconptr);
  245.       popmatrix();
  246.       tmpiconptr = tmpiconptr->nexticon;
  247.       }
  248. }
  249.  
  250. /************************************************************
  251. *
  252. * Streamlined drawscene so picking will be faster.
  253. *
  254. ************************************************************/
  255. void pickdrawscene(int frame)
  256. {
  257.    if (OPENBOOK)
  258.       {
  259.       pushmatrix();
  260.       rot(-25.0, 'x');
  261.       translate(0.0, 1.0, 0.0);
  262.       pickdrawopenframe(frame);
  263.       popmatrix();
  264.       }
  265.    else
  266.       pickdrawshelves();
  267. }
  268.  
  269. /************************************************************
  270. *
  271. *  draws the scene where the current page can be anywhere 
  272. *  in a turn.
  273. *
  274. ************************************************************/
  275. void drawscene(int frame)
  276. {
  277.    dobookview();
  278.    c3s(morecolors[Black]);
  279.    clear();
  280.    if (OPENBOOK)
  281.       {
  282.       setcovercolor(curgroup);
  283.       pushmatrix();
  284.       rot(-25.0, 'x'); 
  285.       translate(0.0, 1.0, 0.0);
  286.       drawopenframe(frame);
  287.       popmatrix();
  288.       }
  289.    else
  290.       drawbookcase();
  291.    swapbuffers();
  292. }
  293.